/**
 * 
 */
package org.jinion.database;

import java.sql.Types;

/**
 * This Enum shows all supported data types.
 * @author zhlmmc
 *
 */
public enum DataType {
	Integer(Types.INTEGER),
	String(Types.VARCHAR),
	Date(Types.DATE),
	Time(Types.TIME),
	UnSupportType(java.lang.Integer.MIN_VALUE);
	
	private int datatypeCode;
	
	private DataType(int typeCode){
		this.datatypeCode = typeCode;
	}
	
	/**
	 * 
	 * @return
	 */
	public int getTypeCode(){
		return this.datatypeCode;
	}
	
	/**
	 * 
	 * @param typeCode
	 * @return
	 */
	public static DataType getDataType(int typeCode){
		for (DataType type : DataType.values()) {
			if (type.getTypeCode() == typeCode) {
				return type;
			}
		}
		return DataType.UnSupportType;
	}
	
	public String toString(){
		switch (datatypeCode) {
		case Types.INTEGER:
			return "Integer";
		case Types.VARCHAR:
			return "String";
		case Types.DATE:
			return "Date";
		case Types.TIME:
			return "Time";
		default:
			return "Unsupported Type";
		}
	}
}
